<script setup lang="ts">
import {ref} from "vue";
import type {BusinessReleases} from "@/api/more/model/indel";
import {Business, businesslist} from "@/api/more";
import LoginPage from "@/views/Login/LoginPage.vue";

const num =Math.floor(Math.random() * 100000)
const username = ref<any>('');
const Instructions = ref<any>('');
const message = ref<any>('');
const value = ref<any>([]);
const img =ref<any>('')

// console.log(Instructions.value)
// console.log(message.value)
// const onSubmit = (values) => {
//
//     // console.log('submit', values);
//          console.log(id2.value)
//     Business(id2.value).then(res=>{
//         console.log(res,values)
//         username.value = ''
//         Instructions.value = ''
//         message.value = ''
//     })
// };
// businesslist().then(res=>{
//     console.log(res)
// })
function submit(){
    let id2 = ref<BusinessReleases>({
        releaseId:num,
        title:username.value,
        intro:Instructions.value,
        contentRich:message.value,
    })
    Business(id2.value).then(res=> {
        console.log(res)
        username.value = ''
        Instructions.value = ''
        message.value = ''

    })
}

// function demo(){
//     console.log(value.value)
// }
</script>

<template>
    <div>
        <div class="main">
            <van-form>
                <van-cell-group inset>
                    <van-field
                        v-model="username"
                        name="业务名称"
                        label="业务名称"
                        placeholder="请输入业务名称"
                        :rules="[{ required: true, message: '请输入业务名称' }]"
                    />
                    <van-field
                        v-model="Instructions"
                        type="text"
                        name="业务说明"
                        label="业务说明"
                        placeholder="请输入业务说明"
                        :rules="[{ required: true, message: '请输入业务说明' }]"
                    />
                    <van-field
                        name="uploader"
                        label="展示封面"
                        :rules="[{ required: true, message: '请添加图片' }]"
                    >
                        <template #input>
                            <van-uploader v-model="value"/>
                        </template>
                    </van-field>
                </van-cell-group>
                <label for="">留言</label>
                <van-cell-group inset>
                    <van-field
                        class="bg"
                        v-model="message"
                        rows="1"
                        autosize
                        type="textarea"
                        maxlength="300"
                        placeholder="请输入留言"
                        :rules="[{ required: true, message: '请输入留言' }]"
                    />
                </van-cell-group>

                <div style="margin: 16px;">
                    <van-button round block type="primary" native-type="submit" @click="submit">
                        提交
                    </van-button>
                </div>
            </van-form>
        </div>
<!--        <button @click="demo">按钮</button>-->
    </div>
</template>

<style scoped>
.bg{
    background-color: #f7f8fa;
}
.main{
    width: 350px;
    //height: 505px;
    margin: 20px auto;
    border-radius: 5px;
    background-color: white;
}
label{
    margin-left: 30px;
}
</style>